package com.crud.service;

import com.crud.dao.BookMapper;
import com.crud.entity.Book;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("bookService")
public class BookServiceImpl implements BookService {
    /*通过Spring把BooksMapper注入给Service*/
    @Resource(name="bookMapper")
    private BookMapper bookMapper;

    public void setBooksMapper(BookMapper booksMapper) {
        this.bookMapper = booksMapper;
    }

    @Override
    public boolean addBook(Book book) {
        if (bookMapper.addBook(book)>0)
            return true;
        return false;
    }

    @Override
    public boolean delBookById(Integer id) {
        if (bookMapper.delBookById(id)>0)
            return true;
        return false;
    }

    @Override
    public boolean updateBook(Book book) {
        if (bookMapper.updateBook(book)>0)
            return true;
        return false;
    }

    @Override
    public Book queryBookById(Integer id) {
        return bookMapper.queryBookById(id);
    }

    @Override
    public List<Book> queryAllBooks() {
        return bookMapper.queryAllBooks();
    }

    @Override
    public List<Book> queryBookByName(String bookName) {
        return bookMapper.queryBookByName(bookName);
    }
}
